﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SummerTraining
{
    public partial class Form1 : Form
    {
        private List<string> errMsg = new List<string>();
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            errMsg.Clear();

            int i = ProcessText(textBox1.Text, "请输入正确的加数");


            int j = ProcessText(textBox2.Text, "请输入正确的被加数");
            if (errMsg.Count > 0)
            {
                string msg = "";
                for (int index = 0; index < errMsg.Count; index++)
                {
                    string s = errMsg[index];
                    if (index != 0)
                    {
                        msg += Environment.NewLine;
                    }
                    msg += s;
                }
                MessageBox.Show(msg);
                return;
            }
            int k = i + j;
            textBox3.Text = k.ToString();
        }

        private int ProcessText(string value, string errorMsg)
        {
            int ret = 0;
            try
            {
                ret = int.Parse(value);





            }
            catch (OverflowException e2)
            {
                MessageBox.Show("太大啦");
            }
            catch (Exception e)
            {
                errMsg.Add(errorMsg);
                throw new MyException("");
            }
            return ret;
        }
    }
}
